<template>
	<view>
		<u-modal :show="show" :title="title" :showCancelButton="true" :showConfirmButton="true" title="置顶时间"
			@confirm="Topping" width="550rpx" @cancel="toCancel" :getContainer="false" confirmColor="red">
			<view class="chooseBox">
				<u-radio-group v-model="value" placement="column">
					<u-radio :customStyle="{marginBottom: '25rpx',fontSize:'24rpx'}" v-for="(item, index) in list"
						:key="item.id" :label="'置顶'+ item.time + (item.name == '1'?'小时':'天')+'消耗金币'+item.coin+'枚'"
						:name="item.id" activeColor="red" labelSize="14">
					</u-radio>
				</u-radio-group>
				<view class="acea-row row-middle row-center coinTxt">
					<text>您的金币还剩：{{myCoin}}</text>
					<text class="cz" @click="toGetCoin">充值</text>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		zdInformation
	} from '@/api/api.js'
	import {
		getCoinList,
		getIndividual
	} from "@/api/api.js"
	import {
		dictionary
	} from "@/api/subletOfShop.js"
	import {
		xxjc
	} from '@/api/api.js'
	export default {
		data() {
			return {
				title: '标题',
				list: [],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				checkedBoxs: [],
				cont: [],
				value: '',
				myCoin: 0
			}

		},
		props: {
			types: {
				type: String,
				default: ''
			},
			linkId: {
				type: Number,
				default: ''
			},
			storeCategory:{
				type: [String,Number],
				default: ''
			},
			status:{
				type: [String,Number],
				default: ''
			},
			show: {
				type: Boolean,
				default: false
			}
		},
		watch: {
			show(newVal) {
				if (newVal) {
					this.getConin()
				}
			},
			linkId(newVal) {
				if (this.show) {
					this.value = ''
					this.getDictionary()
				}
			}
		},
		created() {
			this.getDictionary()
		},
		mounted() {

		},
		methods: {
			getConin() {
				getIndividual().then(res => {
					if (res.code == 200) {
						this.myCoin = res.data.integral;
					}

				})
			},
			//置顶
			Topping() {
				// let item = this.item
				let that = this;
				// if (item.sort == 1) {
				// 	return;
				// }
				zdInformation(this.types, {
					id: this.linkId,
					askrentId:this.linkId,
					buystoreId: this.linkId,
					sort: 1,
					dictionary: this.value,
					storeCategory: this.storeCategory,
					status: this.status
				}).then(res => {
					if (res.code == 200) {
						that.toCancel()
						that.$emit('opear', res.message)
					}
				}).catch(e => {
					that.$util.Tips({
						title: e
					})

					if (e.indexOf('金币不足') != -1) {
						setTimeout(() => {
							this.toGetCoin()
						},1500)
					}


				})

			},
			toGetCoin() {
				uni.navigateTo({
					url: '/pages/aboutUsers/userGoldcoin/userGoldcoin'
				})
			},
			open() {
				this.show = true;

			},
			checkboxChange(e) {
				this.cont = e;

			},
			toConfirm() {
				console.log("to------确定")
				// let params ={
				// 	type:this.types,
				// 	linkId:this.linkId,
				// 	content: this.cont.join(',')
				// }
				// xxjc(params).then(res=>{
				// 	if(res.code == 200){
				// 		this.show = false;
				// 		this.$util.Tips({
				// 			title:'举报成功'
				// 		})
				// 	}
				// })
			},
			toCancel() {
				this.$emit("close")
			},
			//获取户型字典列表
			async getDictionary() {
				try {
					const {
						data
					} = await dictionary({
						gids: 34
					});
					this.list = data['34']
					this.value = this.list[0].id
					console.log('this.list', this.list)

				} catch (e) {
					//TODO handle the exception
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.chooseBox {
		width: 100%;
		padding: 10rpx 40rpx;
	}

	.coinTxt {
		font-size: 28rpx;

		.cz {
			margin-left: 28rpx;
			color: red;
		}
	}
</style>